﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMSalesManagement
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //生产力动态
            var data = CRM.Business.ContentInfo.GetNewsList(5);
            this.dlNews.DataSource = data;
            this.dlNews.DataBind();
            if (getUrl(data) != null)
            {
                imageNews.ImageUrl = getUrl(data);
            }
            else
            {
                imageNews.ImageUrl = "images/NewImages/new1.jpg";
            }
            //产品展示
            var dataResult =CRM.Business.Product.ProductsShow();
            this.dlResult.DataSource = dataResult;
            this.DataBind();
        }
        private string getUrl(List<CRM.Model.ContentList> newsList)
        {
            string url = null;
            try
            {
                if (newsList != null)
                {
                    foreach (var item in newsList)
                    {
                        if (item.ImgPath != "")
                        {
                            url = item.ImgPath;
                            break;
                        }
                    }
                }                
                return url;                
            }catch(Exception)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('数据读取失败！');</script>");
                return null;
            }
           
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["searchType"] = this.ddlClass.Text.Trim();
            Session["searchContent"] = this.txtContent.Text.Trim();
            Response.Redirect("/FrontPageShow/ProductInforList.aspx");
        }
    }
}